<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/T32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/T16x16.png">
  <link rel="mask-icon" href="/images/T.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"angelatao.github.io","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="基础知识查找排序算法  实验及代码Ex5-1设有序序列的数据元素为：（3，10，13，17，40，43，50，70）  编写顺序查找函数; 编写二分查找函数; 乱序输入元素，编写创建二叉排序树函数和查找函数; 在主程序中输入关键字（例如43和5），分别调用三种查找函数，输出结果。  1234567891011121314151617181920212223242526272829303132333">
<meta property="og:type" content="article">
<meta property="og:title" content="数据结构(5)-查找排序">
<meta property="og:url" content="https://angelatao.github.io/2021/06/28/shujujiegou5/index.html">
<meta property="og:site_name" content="Akali&#39;s Blog">
<meta property="og:description" content="基础知识查找排序算法  实验及代码Ex5-1设有序序列的数据元素为：（3，10，13，17，40，43，50，70）  编写顺序查找函数; 编写二分查找函数; 乱序输入元素，编写创建二叉排序树函数和查找函数; 在主程序中输入关键字（例如43和5），分别调用三种查找函数，输出结果。  1234567891011121314151617181920212223242526272829303132333">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-06-27T18:15:04.000Z">
<meta property="article:modified_time" content="2022-05-19T15:01:52.692Z">
<meta property="article:author" content="Akali">
<meta property="article:tag" content="大二">
<meta property="article:tag" content="数据结构">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://angelatao.github.io/2021/06/28/shujujiegou5/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>数据结构(5)-查找排序 | Akali's Blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Akali's Blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://angelatao.github.io/2021/06/28/shujujiegou5/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/head.png">
      <meta itemprop="name" content="Akali">
      <meta itemprop="description" content="If you look dangerous, you better be dangerous.">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Akali's Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          数据结构(5)-查找排序
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-06-28 02:15:04" itemprop="dateCreated datePublished" datetime="2021-06-28T02:15:04+08:00">2021-06-28</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-05-19 23:01:52" itemprop="dateModified" datetime="2022-05-19T23:01:52+08:00">2022-05-19</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/" itemprop="url" rel="index"><span itemprop="name">数据结构</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/06/28/shujujiegou5/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/06/28/shujujiegou5/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h3 id="基础知识"><a href="#基础知识" class="headerlink" title="基础知识"></a>基础知识</h3><p>查找排序算法</p>
<hr>
<h3 id="实验及代码"><a href="#实验及代码" class="headerlink" title="实验及代码"></a>实验及代码</h3><h4 id="Ex5-1"><a href="#Ex5-1" class="headerlink" title="Ex5-1"></a>Ex5-1</h4><p>设有序序列的数据元素为：<code>（3，10，13，17，40，43，50，70）</code></p>
<ul>
<li>编写顺序查找函数;</li>
<li>编写二分查找函数;</li>
<li>乱序输入元素，编写创建二叉排序树函数和查找函数;</li>
<li>在主程序中输入关键字（例如43和5），分别调用三种查找函数，输出结果。</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;stdlib.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> M 100</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//二叉树结点类型</span></span><br><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span> <span class="title">BTnode</span></span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">    <span class="keyword">int</span> data;</span><br><span class="line">    BTnode *Rchild;</span><br><span class="line">    BTnode *Lchild;</span><br><span class="line">&#125;Btree_node;</span><br><span class="line"></span><br><span class="line"><span class="comment">//二叉树数据结构类型</span></span><br><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span> </span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">    Btree_node *root;</span><br><span class="line">    <span class="keyword">int</span> num;</span><br><span class="line">&#125;Btree_type;</span><br><span class="line"></span><br><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span></span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">    <span class="keyword">int</span> num[M];</span><br><span class="line">    <span class="keyword">int</span> length;</span><br><span class="line">&#125;num_type;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">Bubble_Sort</span><span class="params">(num_type *p)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>; i &lt; p-&gt;length<span class="number">-1</span>; i++)</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">0</span>; j &lt; p-&gt;length<span class="number">-1</span>-i; j++)</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">if</span>(p-&gt;num[j] &gt; p-&gt;num[j+<span class="number">1</span>])     <span class="comment">//相邻两元素比较</span></span><br><span class="line">            &#123;</span><br><span class="line">                <span class="keyword">int</span> temp = p-&gt;num[j];       <span class="comment">//交换元素</span></span><br><span class="line">                p-&gt;num[j] = p-&gt;num[j+<span class="number">1</span>];</span><br><span class="line">                p-&gt;num[j+<span class="number">1</span>] = temp;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//顺序查找</span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">seq_search</span><span class="params">(num_type *p, <span class="keyword">int</span> key)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">int</span> flag = <span class="number">0</span>, i;</span><br><span class="line">    <span class="keyword">for</span>(i=<span class="number">0</span>; i &lt; p-&gt;length; i++)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">if</span>(p-&gt;num[i] == key)</span><br><span class="line">        &#123;</span><br><span class="line">            flag = <span class="number">1</span>;</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span>(flag == <span class="number">1</span>) <span class="keyword">return</span> i+<span class="number">1</span>;</span><br><span class="line">    <span class="keyword">else</span> <span class="keyword">return</span> <span class="number">-1</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//二分查找  返回key的位置</span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">binary_search</span><span class="params">(num_type *p, <span class="keyword">int</span> key)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    Bubble_Sort(p);</span><br><span class="line">    <span class="keyword">int</span> low = <span class="number">0</span>, high = p-&gt;length<span class="number">-1</span>;</span><br><span class="line">    <span class="keyword">int</span> mid = (low + high)/<span class="number">2</span>;</span><br><span class="line">    <span class="keyword">while</span>(low &lt;= high)</span><br><span class="line">    &#123;</span><br><span class="line">        mid = (low + high)/<span class="number">2</span>;</span><br><span class="line">        <span class="keyword">if</span>(p-&gt;num[mid] &gt; key)</span><br><span class="line">            high = mid <span class="number">-1</span>;</span><br><span class="line">        <span class="keyword">if</span>(p-&gt;num[mid] == key)</span><br><span class="line">            <span class="keyword">return</span> mid + <span class="number">1</span>;</span><br><span class="line">        <span class="keyword">if</span>(p-&gt;num[mid] &lt; key) </span><br><span class="line">            low = mid + <span class="number">1</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="number">-1</span>;             </span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//创建二叉排序树</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">BST</span><span class="params">(num_type *p, Btree_type *bst)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    Btree_node *b, *temp;</span><br><span class="line">    bst-&gt;num = p-&gt;length;</span><br><span class="line">    bst-&gt;root = (Btree_node *)<span class="built_in">malloc</span>(<span class="keyword">sizeof</span>(Btree_node));</span><br><span class="line">    bst-&gt;root-&gt;data = p-&gt;num[<span class="number">0</span>];</span><br><span class="line">    bst-&gt;root-&gt;Rchild = <span class="literal">NULL</span>;</span><br><span class="line">    bst-&gt;root-&gt;Lchild = <span class="literal">NULL</span>;</span><br><span class="line">    <span class="comment">//temp = (Btree_node *)malloc(sizeof(Btree_node));</span></span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>; i &lt; p-&gt;length; i++)</span><br><span class="line">    &#123;</span><br><span class="line">        b = (Btree_node *)<span class="built_in">malloc</span>(<span class="keyword">sizeof</span>(Btree_node));</span><br><span class="line">        b-&gt;data = p-&gt;num[i];</span><br><span class="line">        b-&gt;Lchild = <span class="literal">NULL</span>;</span><br><span class="line">        b-&gt;Rchild = <span class="literal">NULL</span>;</span><br><span class="line">        temp = bst-&gt;root;</span><br><span class="line">        <span class="keyword">while</span>(<span class="number">1</span>)</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">if</span>(temp-&gt;data &lt; b-&gt;data)</span><br><span class="line">            &#123;</span><br><span class="line">                <span class="keyword">if</span>(temp-&gt;Rchild == <span class="literal">NULL</span>)</span><br><span class="line">                &#123;</span><br><span class="line">                    temp-&gt;Rchild = b;</span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">else</span> temp = temp-&gt;Rchild;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">else</span></span><br><span class="line">            &#123;</span><br><span class="line">                <span class="keyword">if</span>(temp-&gt;Lchild == <span class="literal">NULL</span>)</span><br><span class="line">                &#123;</span><br><span class="line">                    temp-&gt;Lchild = b;</span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">else</span> temp = temp-&gt;Lchild;  </span><br><span class="line">            &#125;</span><br><span class="line">        &#125;           </span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">//free(temp);  // 不需要</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//二叉树查找</span></span><br><span class="line"><span class="function">Btree_node* <span class="title">BST_search</span><span class="params">(Btree_node *r, <span class="keyword">int</span> key)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(r == <span class="literal">NULL</span>) <span class="keyword">return</span> <span class="literal">NULL</span>;</span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">if</span>(key == r-&gt;data) <span class="keyword">return</span> r;</span><br><span class="line">        <span class="keyword">else</span> <span class="keyword">if</span>(key &lt; r-&gt;data) <span class="keyword">return</span>(BST_search(r-&gt;Lchild, key));</span><br><span class="line">        <span class="keyword">else</span> <span class="keyword">return</span> (BST_search(r-&gt;Rchild, key));</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">destroy_btree</span><span class="params">(Btree_node *root)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(root == <span class="literal">NULL</span>) <span class="keyword">return</span>;</span><br><span class="line">    <span class="keyword">if</span>(root-&gt;Lchild != <span class="literal">NULL</span>) destroy_btree(root-&gt;Lchild);</span><br><span class="line">    <span class="keyword">if</span>(root-&gt;Rchild != <span class="literal">NULL</span>) destroy_btree(root-&gt;Rchild);</span><br><span class="line">    <span class="built_in">free</span>(root);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    num_type n, key;</span><br><span class="line">    n.length = <span class="number">0</span>;</span><br><span class="line">    key.length =<span class="number">0</span>;</span><br><span class="line">    <span class="keyword">int</span> x, k;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;Please enter the element ending with -1\n&quot;</span>);</span><br><span class="line">    <span class="built_in">scanf</span>(<span class="string">&quot;%d&quot;</span>, &amp;x);</span><br><span class="line">    <span class="keyword">while</span>(x != <span class="number">-1</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        n.num[n.length] = x;</span><br><span class="line">        n.length++;</span><br><span class="line">        <span class="built_in">scanf</span>(<span class="string">&quot;%d&quot;</span>, &amp;x);</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;Please enter the key value ending with -1\n&quot;</span>);</span><br><span class="line">    <span class="built_in">scanf</span>(<span class="string">&quot;%d&quot;</span>, &amp;k);</span><br><span class="line">    <span class="keyword">while</span>(k != <span class="number">-1</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        key.num[key.length] = k;</span><br><span class="line">        key.length++;</span><br><span class="line">        <span class="built_in">scanf</span>(<span class="string">&quot;%d&quot;</span>, &amp;k);</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">//建立二叉排序树</span></span><br><span class="line">    Btree_type btr;</span><br><span class="line">    btr.num = <span class="number">0</span>;</span><br><span class="line">    btr.root = <span class="literal">NULL</span>;</span><br><span class="line">    BST(&amp;n, &amp;btr);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>; i &lt; key.length; i++)</span><br><span class="line">    &#123;   </span><br><span class="line">        <span class="comment">//二分查找</span></span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;The result of binary search:     &quot;</span>);</span><br><span class="line">        <span class="keyword">int</span> place1 = binary_search(&amp;n, key.num[i]);</span><br><span class="line">        <span class="keyword">if</span>(place1 &lt; <span class="number">0</span>) <span class="built_in">printf</span>(<span class="string">&quot;%d doesn`t exist\n&quot;</span>, key.num[i]);</span><br><span class="line">        <span class="keyword">else</span> <span class="built_in">printf</span>(<span class="string">&quot;The position of %d in the array is %d\n&quot;</span>, key.num[i], place1);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//顺序查找</span></span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;The result of sequence search:   &quot;</span>);</span><br><span class="line">        <span class="keyword">int</span> place2 = seq_search(&amp;n, key.num[i]);</span><br><span class="line">        <span class="keyword">if</span>(place2 &lt; <span class="number">0</span>) <span class="built_in">printf</span>(<span class="string">&quot;%d doesn`t exist\n&quot;</span>, key.num[i]);</span><br><span class="line">        <span class="keyword">else</span> <span class="built_in">printf</span>(<span class="string">&quot;The position of %d in the array is %d\n&quot;</span>, key.num[i], place2);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//二叉树查找</span></span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;The result of BST search:        &quot;</span>);</span><br><span class="line">        Btree_node* place3 = BST_search(btr.root, key.num[i]);</span><br><span class="line">        <span class="keyword">if</span>(place3 == <span class="literal">NULL</span>) <span class="built_in">printf</span>(<span class="string">&quot;%d doesn`t exist\n&quot;</span>, key.num[i]);</span><br><span class="line">        <span class="keyword">else</span> <span class="built_in">printf</span>(<span class="string">&quot;%d  exists\n&quot;</span>, place3-&gt;data);</span><br><span class="line"></span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;\n&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    destroy_btree(btr.root);</span><br><span class="line">    getchar();</span><br><span class="line">    getchar();</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<hr>
<h4 id="Ex5-2"><a href="#Ex5-2" class="headerlink" title="Ex5-2"></a>Ex5-2</h4><ul>
<li>编写简单选择法函数;</li>
<li>编写直接插入法函数;</li>
<li>编写冒泡法排序函数;</li>
<li>编写快速排序函数;</li>
<li>在主程序中输入一组数据元素（例如：513，87，512，61，908，170，897，275，653，462），分别调用三种排序函数，输出每趟排序结果。</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> M 100</span></span><br><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span> <span class="title">num</span></span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">    <span class="keyword">int</span> num[M];</span><br><span class="line">    <span class="keyword">int</span> length;</span><br><span class="line">&#125;num_type;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">Bubble_Sort</span><span class="params">(num_type *p)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>; i &lt; p-&gt;length<span class="number">-1</span>; i++)</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">0</span>; j &lt; p-&gt;length<span class="number">-1</span>-i; j++)</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">if</span>(p-&gt;num[j] &gt; p-&gt;num[j+<span class="number">1</span>])     <span class="comment">//相邻两元素比较</span></span><br><span class="line">            &#123;</span><br><span class="line">                <span class="keyword">int</span> temp = p-&gt;num[j];       <span class="comment">//交换元素</span></span><br><span class="line">                p-&gt;num[j] = p-&gt;num[j+<span class="number">1</span>];</span><br><span class="line">                p-&gt;num[j+<span class="number">1</span>] = temp;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">Selection_sort</span><span class="params">(num_type *p)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">int</span> min, nummin;</span><br><span class="line">    <span class="keyword">int</span> temp;</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">0</span>; j &lt; p-&gt;length<span class="number">-1</span>; j++)</span><br><span class="line">    &#123;</span><br><span class="line">        nummin = p-&gt;num[j];</span><br><span class="line">        min = j;</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> i=j; i &lt; p-&gt;length<span class="number">-1</span>; i++)</span><br><span class="line">        &#123;</span><br><span class="line">            </span><br><span class="line">            <span class="keyword">if</span>(p-&gt;num[i+<span class="number">1</span>] &lt; nummin)</span><br><span class="line">            &#123;</span><br><span class="line">                min = i+<span class="number">1</span>;             <span class="comment">//找出最小值的位置</span></span><br><span class="line">                nummin = p-&gt;num[i+<span class="number">1</span>];</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        temp = p-&gt;num[min];      <span class="comment">//交换最小值和第一个元素的位置</span></span><br><span class="line">        p-&gt;num[min] = p-&gt;num[j];</span><br><span class="line">        p-&gt;num[j] = temp;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">Insertion_Sort</span><span class="params">(num_type *p)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> i=p-&gt;length<span class="number">-1</span>; i &gt;= <span class="number">0</span>; i--)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> j=i<span class="number">-1</span>; j &gt;= <span class="number">0</span>; j--)</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">if</span>(p-&gt;num[i] &lt; p-&gt;num[j])</span><br><span class="line">            &#123;</span><br><span class="line">                <span class="keyword">int</span> temp = p-&gt;num[i];</span><br><span class="line">                p-&gt;num[i] = p-&gt;num[j];</span><br><span class="line">                p-&gt;num[j] = temp;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">Quick</span><span class="params">(<span class="keyword">int</span> num[], <span class="keyword">int</span> start, <span class="keyword">int</span> end)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(start &lt; end)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">int</span> low = start;</span><br><span class="line">        <span class="keyword">int</span> high = end;</span><br><span class="line">        <span class="comment">//快排分区操作</span></span><br><span class="line">        <span class="keyword">int</span> temp = num[low];     <span class="comment">//取第一位为基准</span></span><br><span class="line">        <span class="keyword">while</span>(low &lt; high)       <span class="comment">//相等时分区操作完成</span></span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">while</span>(low &lt; high &amp;&amp; num[high] &gt; temp)    <span class="comment">//遍历找到比temp小的       </span></span><br><span class="line">                high--;</span><br><span class="line">            <span class="keyword">if</span>(low &gt; high) <span class="keyword">break</span>;</span><br><span class="line">            <span class="keyword">else</span> </span><br><span class="line">                num[low] = num[high];</span><br><span class="line">            <span class="keyword">while</span>(low &lt; high &amp;&amp; num[low] &lt; temp)</span><br><span class="line">                low++;</span><br><span class="line">            <span class="keyword">if</span>(low &gt; high) <span class="keyword">break</span>;</span><br><span class="line">            <span class="keyword">else</span></span><br><span class="line">                num[high] = num[low];</span><br><span class="line">           </span><br><span class="line">        &#125;</span><br><span class="line">        num[low] = temp;</span><br><span class="line">        Quick(num, start, low<span class="number">-1</span>);</span><br><span class="line">        Quick(num, low+<span class="number">1</span>, end);    <span class="comment">//递归实现</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">Quick_Sort</span><span class="params">(num_type *p)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    Quick(p-&gt;num, <span class="number">0</span>, p-&gt;length<span class="number">-1</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">print_num</span><span class="params">(num_type *p)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>; i &lt; p-&gt;length; i++)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;%d &quot;</span>, p-&gt;num[i]);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;\n&quot;</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    num_type s1, s2, s3, s4;</span><br><span class="line">    s1.length = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">int</span> x, i = <span class="number">0</span>;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;Please enter the element ending with 0\n&quot;</span>);</span><br><span class="line">    <span class="built_in">scanf</span>(<span class="string">&quot;%d&quot;</span>, &amp;x);</span><br><span class="line">    <span class="keyword">while</span>(x != <span class="number">0</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        s1.num[i] = x;</span><br><span class="line">        s2.num[i] = x;</span><br><span class="line">        s3.num[i] = x;</span><br><span class="line">        s4.num[i] = x;</span><br><span class="line">        <span class="built_in">scanf</span>(<span class="string">&quot;%d&quot;</span>, &amp;x);</span><br><span class="line">        s1.length++;</span><br><span class="line">        s2.length = s1.length;</span><br><span class="line">        s3.length = s1.length;</span><br><span class="line">        s4.length = s1.length;</span><br><span class="line">        i++;</span><br><span class="line">    &#125;</span><br><span class="line">    Selection_sort(&amp;s1);</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;选择排序的结果：&quot;</span>);</span><br><span class="line">    print_num(&amp;s1);</span><br><span class="line">    Insertion_Sort(&amp;s2);</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;插入排序的结果：&quot;</span>);</span><br><span class="line">    print_num(&amp;s2);</span><br><span class="line">    Bubble_Sort(&amp;s3);</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;冒泡排序的结果：&quot;</span>);</span><br><span class="line">    print_num(&amp;s3);</span><br><span class="line">    Quick_Sort(&amp;s4);</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;快速排序的结果：&quot;</span>);</span><br><span class="line">    print_num(&amp;s4);</span><br><span class="line">    getchar();</span><br><span class="line">    getchar();</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<hr>

    </div>

    
    
    
        <div class="reward-container">
  <div>良心博主，一杯快乐水足矣。</div>
  <button onclick="var qr = document.getElementById('qr'); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">
    打赏
  </button>
  <div id="qr" style="display: none;">
      
      <div style="display: inline-block;">
        <img src="/images/wechatpay.png" alt="Akali 微信支付">
        <p>微信支付</p>
      </div>
      
      <div style="display: inline-block;">
        <img src="/images/alipay.png" alt="Akali 支付宝">
        <p>支付宝</p>
      </div>

  </div>
</div>

        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>Akali
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://angelatao.github.io/2021/06/28/shujujiegou5/" title="数据结构(5)-查找排序">https://angelatao.github.io/2021/06/28/shujujiegou5/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/tags/%E5%A4%A7%E4%BA%8C/" rel="tag"><i class="fa fa-tag"></i> 大二</a>
              <a href="/tags/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/" rel="tag"><i class="fa fa-tag"></i> 数据结构</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021/06/27/shujujiegou4/" rel="prev" title="数据结构(4)-二叉树">
      <i class="fa fa-chevron-left"></i> 数据结构(4)-二叉树
    </a></div>
      <div class="post-nav-item">
    <a href="/2022/03/28/machine-learning1/" rel="next" title="机器学习-聚类分析">
      机器学习-聚类分析 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>
      <!-- none-select-br -->

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86"><span class="nav-number">1.</span> <span class="nav-text">基础知识</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%AE%9E%E9%AA%8C%E5%8F%8A%E4%BB%A3%E7%A0%81"><span class="nav-number">2.</span> <span class="nav-text">实验及代码</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#Ex5-1"><span class="nav-number">2.1.</span> <span class="nav-text">Ex5-1</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Ex5-2"><span class="nav-number">2.2.</span> <span class="nav-text">Ex5-2</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Akali"
      src="/images/head.png">
  <p class="site-author-name" itemprop="name">Akali</p>
  <div class="site-description" itemprop="description">If you look dangerous, you better be dangerous.</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">8</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">1</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">4</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/Angelatao" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;Angelatao" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>



      </div>
      
      <p></p>
      <!-- hitokoto -->
      <div class="hitokoto-title">
        <i class="fa fa-paragraph"></i>
        <b>每日一言</b>
      </div>

      <div id="hitokoto">:D 获取中...</div>
      <i id="hitofrom">:D 获取中...</i>

      <script src="https://cdn.jsdelivr.net/npm/bluebird@3/js/browser/bluebird.min.js"></script>
      <script src="https://cdn.jsdelivr.net/npm/whatwg-fetch@2.0.3/fetch.min.js"></script>
      <script>
        fetch('https://v1.hitokoto.cn')
          .then(function (res){
            return res.json();
          })
          .then(function (data) {
            var hitokoto = document.getElementById('hitokoto');
            hitokoto.innerText = '\xa0\xa0\xa0\xa0\xa0\xa0\xa0' + data.hitokoto;
            var hitofrom = document.getElementById('hitofrom');
            hitofrom.innerText = "——" + data.from + '\xa0'; 
          })
          .catch(function (err) {
            console.error(err);
          })
      </script>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Akali</span>
</div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'yIs65LhYor8kK3wvgY6sa885-gzGzoHsz',
      appKey     : 'gPJ3LQUAa7zeY7JqgWT0c7tS',
      placeholder: "欢迎留言评论...",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : false,
      lang       : '' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
